package com.daowen.bll;

import com.daowen.dal.DALBase;
import com.daowen.entity.Leaveword;

import java.text.MessageFormat;
import java.util.Date;
import java.util.Iterator;
import java.util.List;

public class LeavewordBLL {

    public static String getLeaveword(){

        StringBuffer sb=new StringBuffer();
        sb.append("<ul >");
        List list=DALBase.getEntity("leaveword", "");

        for(Iterator<Leaveword> it=list.iterator();it.hasNext();)
        {
            Leaveword c=it.next();
            sb.append("<li class=\"item\">");
            sb.append(MessageFormat.format("<img class=\"avatar\" src=\"{0}\" />",c.getPhoto()));

            sb.append("<div class='body'>");
            sb.append("<div class=\"head\"></div>");
            sb.append("<div class=\"content\">");
            sb.append(MessageFormat.format("<span class=\"user-info\">{0}</span>",c.getLwren()));
            String times="";
            long time=new Date().getTime()- c.getPubtime().getTime();
            time=time/1000;//转成秒
            long day = time/(60*60*24);//转换成天
            time=time%(60*60*24);//剩下多少秒
            long hour=time/(60*60);//转换成时间
            time=time%(60*60);//剩下多少秒
            long minuter=time/60;//剩下多少分钟
            if(minuter!=0){
                times=minuter+"分钟前";
            }
            if(hour!=0){
                times=hour+"小时前";
            }
            if(day!=0){
                times=day+"天前";
            }
            sb.append(MessageFormat.format("<span class=\"pubtime\">{0}</span>",times));
            sb.append("<div class='data-info'>");
            sb.append(c.getDcontent());
            //end data-info
            sb.append("</div>");
            //
            if(c.getStatus()==1)
            {
                sb.append("<div class=\"reply\">");
                sb.append(MessageFormat.format("<div>回复内容：{0}</div>", c.getReplycontent()));
                sb.append("</div>");
            }

            sb.append("<div class=\"footer\"></div>");
            //end content
            sb.append("</div>");

            //end body
            sb.append("</div>");


            sb.append("</li>");


        }
        sb.append("</ul>");

        return sb.toString();



    }


}
